package com.wc.AlgoOJ.CT0208;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/19 12:17
 * @description blg出烂题Ⅰ
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] a = new int[N], b = new int[N];
    static int n, m;

    // 思路：
    // 当 m == 1 的时候, 就是a[n] - a[1]
    // 当 m > 1, 假设从i处避开 那就是 a[n] - a[i+1] + a[i] - a[1] = a[n] - a[1] - (a[i + 1] - a[i])
    // a[n] - a[1] 是控制不了的,但是可以控制a[i + 1] - a[i] 是不
    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            b[i] = a[i] - a[i - 1];
        }
        long res = a[n] - a[1];
        // 第一个是不能剪开的，因为前面已经没有了
        Arrays.sort(b, 2, n + 1);
        // 减 m - 1次，就分组成了m个
        for (int i = 1, j = n; i < m; i++, j--) {
            res -= b[j];
        }
        out.println(res);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}